package com.yl.auth.service.impl;

import com.yl.auth.entity.YuangongBumen;
import com.yl.auth.mapper.YuangongBumenMapper;
import com.yl.auth.mapper.YuangongMapper;
import com.yl.auth.model.entity.Yuangong;
import com.yl.auth.service.YuangongBumenService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author W
 * @since 2023-07-06
 */
@Service
public class YuangongBumenServiceImpl extends ServiceImpl<YuangongBumenMapper, YuangongBumen> implements YuangongBumenService {
    @Resource
    private YuangongMapper yuangongMapper;
    @Override
    public void updateBuMen(Long id, List<Integer> bumenList) {
        if(id!=null){
            //先删除中间表数据在添加
            yuangongMapper.deleteBuMen(id);
            if(bumenList!=null&&bumenList.size()>0){
                for (Integer bumenid : bumenList) {
                    yuangongMapper.addCenterBuMen(id,bumenid);
                }
            }
        }
    }

    @Override
    public void updateGangWei(Long id, List<Integer> gangweiList) {
        if(id!=null){
            yuangongMapper.deleteGangWei(id);
            if(gangweiList!=null&&gangweiList.size()>0){
                for (Integer gangweiid : gangweiList) {
                    yuangongMapper.addCenterGangWei(id,gangweiid);
                }
            }
        }
    }
    @Override
    public void addBuMen(Long id, List<Integer> bumenList) {
        if(bumenList!=null&&bumenList.size()>0){
            for (Integer bumenid : bumenList) {
                yuangongMapper.addCenterBuMen(id,bumenid);
            }
        }
    }

    @Override
    public void addGangWei(Long id, List<Integer> gangweiList) {
        if(gangweiList!=null&&gangweiList.size()>0){
            for (Integer gangweiid : gangweiList) {
                yuangongMapper.addCenterGangWei(id,gangweiid);
            }
        }
    }
}
